package com.wyp168.leetcode;

/**
 * @ClassName CountConsistentStringsSolution
 * @Title TODO
 * @Description TODO
 * @Author wyp168
 * @Date 2022/11/8 00:08
 */
public class CountConsistentStringsSolution {
    public static void main(String[] args) {
        CountConsistentStringsSolution solution = new CountConsistentStringsSolution();
        String allowed = "cad";
        String[] words = {"cc","acd","b","ba","bac","bad","ac","d"};
        System.out.println(solution.countConsistentStrings(allowed, words));
    }

    public int countConsistentStrings(String allowed, String[] words) {
        int count = 0;
        for (String word : words) {
            int i = 0;
            while (i < word.length() - 1) {
                String substring = word.substring(i, i + 1);
                if (!allowed.contains(substring)) {
                    break;
                }
                i ++;
            }
            if (i == word.length() - 1) {
                if (allowed.contains(word.substring(word.length() - 1))) {
                    count ++;
                }
            }
        }
        return count;
    }
}
